from sqlalchemy import create_engine, Column
import sqlalchemy
# from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import declarative_base
import json

engine = create_engine("mysql://root:root@localhost/test", echo=True)
Base = declarative_base()

class Person(Base):

    __tablename__ = "person"

    id = Column(sqlalchemy.Integer, primary_key=True)
    name = Column(sqlalchemy.String, nullable=False, unique=True)

    def __repr__(self) -> str:
        return json.dumps({"id":self.id, "name":self.name})

Base.metadata.create_all(engine)

Session = sessionmaker(bind=engine)


session = Session()

result_set = session.query(Person).all()

for ret in result_set:
    print(ret)

